package org.acme.bean.dto;

import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
public class BaseResponse<T> {

	public static final String CODE_SUCCESS = "0";
	public static final String CODE_FAIL = "1";
	public static final String MSG_ERROR = "服务内部错误";

	String code;
	String msg;
	T data;

	public BaseResponse (String code, String msg){
		this.code = code;
		this.msg = msg;
	}

	public BaseResponse (String code, String msg, T data){
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public static <T> BaseResponse<T> success(){
		return new BaseResponse<T>(CODE_SUCCESS, null);
	}

	public static <T> BaseResponse<T> success(T data){
		return new BaseResponse<T>(CODE_SUCCESS, null, data);
	}

	public static <T> BaseResponse<T> failed(){
		return new BaseResponse<>(CODE_FAIL, null);
	}

	public static <T> BaseResponse<T> failed(String msg){
		return new BaseResponse<>(CODE_FAIL, msg);
	}

}
